package com.yujistu.framework.helper;

import android.app.Activity;
import android.app.AlertDialog;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import com.yujistu.R;

/**
 * Created by S3YOGA on 2015/11/3.
 */
public class DialogHelper {

    private final Activity mActivity;
    private AlertDialog mAlertDialog;
    private Toast mToast;

    public DialogHelper(Activity activity) {
        this.mActivity = activity;
    }

    /**
     * TOAST
     *
     * @param msg    消息
     * @param period 时长
     */
    public void toast(final String msg, final int period) {
        mActivity.runOnUiThread(new Runnable() {

            @Override
            public void run() {
                if (mToast != null) mToast.cancel();
                mToast = new Toast(mActivity);
                View view = LayoutInflater.from(mActivity).inflate(R.layout.comm_transient_notification,
                        null);
                TextView tv = (TextView) view.findViewById(android.R.id.message);
                tv.setText(msg);
                mToast.setView(view);
                mToast.setDuration(period);

                mToast.setGravity(Gravity.CENTER, 0, 0);
                mToast.show();
            }
        });
    }
}
